package com.work.demo.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.work.demo.entity.Imsvalues;
import com.work.demo.service.ImsvaluesService;
import com.work.demo.mapper.ImsvaluesMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
* @author fulls
* @description 针对表【imsvalues】的数据库操作Service实现
* @createDate 2023-04-24 13:46:43
*/
@Service
@Slf4j
public class ImsvaluesServiceImpl extends ServiceImpl<ImsvaluesMapper, Imsvalues>
    implements ImsvaluesService {

    @Override
    public boolean saveOrUpdate(Imsvalues imsvalues) {
        Imsvalues imsEntity = baseMapper.selectOne(new LambdaQueryWrapper<Imsvalues>()
                .eq(Imsvalues::getCorporationcode, imsvalues.getCorporationcode())
                .eq(Imsvalues::getImsvalue, imsvalues.getImsvalue()));
        if (ObjectUtil.isNotNull(imsEntity)) {
            int update = baseMapper.update(imsvalues, new LambdaUpdateWrapper<Imsvalues>().eq(Imsvalues::getImsvalue, imsvalues.getImsvalue()));
            return update > 0;
        } else {
            int insert = baseMapper.insert(imsvalues);
            return insert > 0;
        }
    }

    @Override
    public void selectAll() {
        List<Imsvalues> list = this.list(Wrappers.<Imsvalues>lambdaQuery()
                .in(Imsvalues::getDeleted, Arrays.asList(0, 1))
        );
        log.info("selectAll --->list:{}", JSONUtil.toJsonStr(list));
    }
}




